<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$plugin_name = $_RQ['basicname'] ? $_RQ['basicname'] : '';
if($_RQ['op']=='get'){
	//显示统计数据
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$mounthtime =  mktime(0,0,0,date('m'),1,date('Y'));
		$access=array();
		$access['workernum']=pdo_count('jy_scrm_worker',array('uniacid'=>$_SESSION['uniacid']));
		$access['membernum']=pdo_count('jy_scrm_member',array('uniacid'=>$_SESSION['uniacid']));
		$access['qunnum']=pdo_count('jy_scrm_qun',array('uniacid'=>$_SESSION['uniacid']));
		$access['qunusernum']=pdo_getsum('jy_scrm_qun',array('uniacid'=>$_SESSION['uniacid']),'num');
		$access['huo_day']=pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'this'=>2,'plugin'=>$_RQ['plugin'],'os'=>5,'createtime >'=>$daytime));
		//月份
		for($i=0;$i<12;$i++){
				if($i==0){
					$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
					$yueend = time();
					
				}else{
					$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
					$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
				}
				$params=$allparams=array('uniacid'=>$_SESSION['uniacid']);
				$params['createtime between']=array($yuestart,$yueend);
				$month12[$i] = date('Y-m',strtotime('-'.$i.' month'));
				$allparams['createtime <=']=$yueend;
				$members[$i]=pdo_count('jy_scrm_member',$allparams);
				$newmembers[$i]=pdo_count('jy_scrm_member',$params);
				$heiparams=$params;
				$heiparams['isblack']=1;
				$heimembers[$i]=pdo_count('jy_scrm_member',$heiparams);
				$quns[$i]=pdo_count('jy_scrm_qun',$allparams);
				$qunnums[$i]=pdo_getsum('jy_scrm_qun',$allparams,'num');
				$newqunnums[$i]=pdo_getsum('jy_scrm_qun',$params,'num');
				$tuiqunnums[$i]=pdo_count('jy_scrm_qun',$params);
				$huos[$i]=pdo_count('jy_scrm_member',$params);
		}
		
		$accessline=array_reverse($accessline);
		$month12=array_reverse($month12);
		$members=array_reverse($members);
		$newmembers=array_reverse($newmembers);
		$heimembers=array_reverse($heimembers);
		$quns=array_reverse($quns);
		$qunnums=array_reverse($qunnums);
		$newqunnums=array_reverse($newqunnums);
		$tuiqunnums=array_reverse($tuiqunnums);
		$huos=array_reverse($huos);
		$return['htmls']=array(
				array('type'=>'data','one_num'=>3,'title'=>'流量池数据指标','datas'=>array(
					array('title'=>'员工总数','data'=>$access['workernum']),
					array('title'=>'企业微信好友总数','data'=>$access['membernum']),
					array('title'=>'社群总数','data'=>$access['qunnum']),
					array('title'=>'群成员总数','data'=>$access['qunusernum']),
				)),
				array('type'=>'data','one_num'=>4,'title'=>'私域流量池活跃指标','datas'=>array(
					array('title'=>'昨日活跃值','data'=>$access['huo_day']),
					array('title'=>'近7日活跃值','data'=>$access['huo_day7']),
					array('title'=>'近30日活跃值','data'=>$access['huo_day30']),
				)),
				array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'时间序列图','datas'=>array(
					'datas'=>array(
						array('name'=>'累计好友数','value'=>$members),
						array('name'=>'新增好友数','value'=>$newmembers),
						array('name'=>'被删除/拉黑','value'=>$heimembers),
						array('name'=>'累计客户群数','value'=>$quns),
						array('name'=>'累计群成员数','value'=>$qunnums),
						array('name'=>'新群成员数','value'=>$newqunnums),
						//array('name'=>'退群成员数','value'=>$tuiqunnums),
						array('name'=>'活跃值','value'=>$huos),
					),
					'xdatas'=>$month12,
				)),
		);
		exi($return);
}